<!DOCTYPE html>
{% load static %}
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>实验室门禁系统 - 卡片录入</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css">
    <style>
        :root {
            --primary-color: #4e73df;
            --secondary-color: #1cc88a;
            --danger-color: #e74a3b;
            --warning-color: #f6c23e;
            --info-color: #36b9cc;
        }
        
        body {
            font-family: 'Nunito', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
            background-color: #f8f9fc;
        }
        
        .sidebar {
            min-height: 100vh;
            background: linear-gradient(180deg, var(--primary-color) 10%, #224abe 100%);
            color: white;
            position: fixed;
            width: 250px;
        }
        
        .sidebar .nav-link {
            color: rgba(255, 255, 255, 0.8);
            padding: 1rem;
            transition: all 0.2s;
        }
        
        .sidebar .nav-link:hover {
            color: white;
            background-color: rgba(255, 255, 255, 0.1);
        }
        
        .sidebar .nav-link.active {
            color: white;
            font-weight: bold;
        }
        
        .sidebar .sidebar-brand {
            height: 4.375rem;
            text-decoration: none;
            font-size: 1.2rem;
            font-weight: 800;
            padding: 1.5rem 1rem;
            text-align: center;
            letter-spacing: 0.05rem;
            color: white;
        }
        
        .main-content {
            margin-left: 250px;
            padding: 1.5rem;
        }
        
        .card {
            border: none;
            border-radius: 0.35rem;
            box-shadow: 0 0.15rem 1.75rem 0 rgba(58, 59, 69, 0.15);
            margin-bottom: 1.5rem;
        }
        
        .card-header {
            background-color: #f8f9fc;
            border-bottom: 1px solid #e3e6f0;
            padding: 0.75rem 1.25rem;
        }
        
        .card-header h6 {
            font-weight: 700;
            margin: 0;
            color: #4e73df;
        }
        
        .card-body {
            padding: 1.25rem;
        }
        
        .user-info {
            padding: 1rem;
            border-bottom: 1px solid rgba(255, 255, 255, 0.1);
            margin-bottom: 1rem;
        }
        
        .user-info .user-name {
            font-weight: bold;
            font-size: 1.1rem;
        }
        
        .form-control:focus {
            border-color: var(--primary-color);
            box-shadow: 0 0 0 0.25rem rgba(78, 115, 223, 0.25);
        }
        
        .btn-primary {
            background-color: var(--primary-color);
            border-color: var(--primary-color);
        }
        
        .btn-primary:hover {
            background-color: #2e59d9;
            border-color: #2e59d9;
        }
        
        .card-animation {
            position: relative;
            height: 200px;
            margin-bottom: 1.5rem;
            perspective: 1000px;
        }
        
        .card-animation .card-visual {
            width: 320px;
            height: 200px;
            position: absolute;
            top: 0;
            left: 50%;
            transform: translateX(-50%) rotateY(0deg);
            background: linear-gradient(135deg, #4e73df, #224abe);
            border-radius: 10px;
            box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);
            color: white;
            padding: 20px;
            transition: transform 0.6s;
            transform-style: preserve-3d;
        }
        
        .card-animation:hover .card-visual {
            transform: translateX(-50%) rotateY(15deg);
        }
        
        .card-visual .chip {
            width: 50px;
            height: 40px;
            background-color: rgba(255, 255, 255, 0.2);
            border-radius: 5px;
            margin-bottom: 20px;
        }
        
        .card-visual .card-number {
            font-size: 1.2rem;
            letter-spacing: 2px;
            margin-bottom: 20px;
        }
        
        .card-visual .card-info {
            display: flex;
            justify-content: space-between;
        }
        
        .alert-success, .alert-danger {
            border-left: 0.25rem solid;
            border-radius: 0.35rem;
        }
        
        .alert-success {
            border-left-color: var(--secondary-color);
        }
        
        .alert-danger {
            border-left-color: var(--danger-color);
        }
        
        @media (max-width: 768px) {
            .sidebar {
                width: 100%;
                position: relative;
                min-height: auto;
            }
            
            .main-content {
                margin-left: 0;
            }
        }
    </style>
</head>
<body>
    <!-- 侧边栏 -->
    <div class="sidebar">
        <a href="#" class="sidebar-brand">
            <i class="bi bi-shield-lock"></i> 实验室门禁系统
        </a>
        
        <div class="user-info">
            <div class="user-name">{{ username }}</div>
            <small>欢迎回来</small>
        </div>
        
        <ul class="nav flex-column">
            <li class="nav-item">
                <a class="nav-link" href="{% url 'back:dashboard' %}">
                    <i class="bi bi-speedometer2 me-2"></i> 控制面板
                </a>
            </li>
            <li class="nav-item">
                <a class="nav-link active" href="{% url 'back:write_card' %}">
                    <i class="bi bi-credit-card me-2"></i> 卡片录入
                </a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="{% url 'back:write_finger' %}">
                    <i class="bi bi-fingerprint me-2"></i> 指纹录入
                </a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="{% url 'back:write_password' %}">
                    <i class="bi bi-key me-2"></i> 密码设置
                </a>
            </li>
            <li class="nav-item mt-5">
                <a class="nav-link" href="{% url 'back:logout' %}">
                    <i class="bi bi-box-arrow-right me-2"></i> 退出登录
                </a>
            </li>
        </ul>
    </div>
    
    <!-- 主内容区 -->
    <div class="main-content">
        <div class="d-flex justify-content-between align-items-center mb-4">
            <h1 class="h3 mb-0 text-gray-800">卡片录入</h1>
        </div>
        
        <!-- 卡片动画 -->
        <div class="card-animation">
            <div class="card-visual">
                <div class="chip"></div>
                <div class="card-number" id="preview-card-number">XXXX XXXX XXXX XXXX</div>
                <div class="card-info">
                    <div>
                        <small>持卡人</small>
                        <div id="preview-information">未设置</div>
                    </div>
                    <div>
                        <i class="bi bi-wifi fs-3"></i>
                    </div>
                </div>
            </div>
        </div>
        
        <!-- 卡片录入表单 -->
        <div class="card">
            <div class="card-header">
                <h6 class="m-0 font-weight-bold">录入新卡片</h6>
            </div>
            <div class="card-body">
                {% if error %}
                <div class="alert alert-danger">
                    <i class="bi bi-exclamation-triangle-fill me-2"></i> {{ error }}
                </div>
                {% endif %}
                
                {% if success %}
                <div class="alert alert-success">
                    <i class="bi bi-check-circle-fill me-2"></i> {{ success }}
                </div>
                {% endif %}
                
                <form method="post">
                    {% csrf_token %}
                    <div class="mb-3">
                        <label for="card_number" class="form-label">卡号</label>
                        <div class="input-group">
                            <span class="input-group-text"><i class="bi bi-credit-card"></i></span>
                            <input type="text" class="form-control" id="card_number" name="card_number" placeholder="请输入卡号" required>
                        </div>
                        <small class="text-muted">请输入卡片上的唯一标识号码</small>
                    </div>
                    
                    <div class="mb-3">
                        <label for="information" class="form-label">持卡人信息</label>
                        <div class="input-group">
                            <span class="input-group-text"><i class="bi bi-person"></i></span>
                            <input type="text" class="form-control" id="information" name="information" placeholder="请输入持卡人信息" required>
                        </div>
                        <small class="text-muted">可以是姓名、学号或其他标识信息</small>
                    </div>
                    
                    <div class="d-grid">
                        <button type="submit" class="btn btn-primary">
                            <i class="bi bi-save me-2"></i> 保存卡片信息
                        </button>
                    </div>
                </form>
            </div>
        </div>
        
        <!-- 已录入卡片列表 -->
        <div class="card">
            <div class="card-header">
                <h6 class="m-0 font-weight-bold">最近录入的卡片</h6>
            </div>
            <div class="card-body">
                <div class="table-responsive">
                    <table class="table table-bordered table-hover">
                        <thead>
                            <tr>
                                <th>卡号</th>
                                <th>持卡人信息</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tbody>
                            {% if card %}
                            <tr>
                                <td>{{ card.card_number }}</td>
                                <td>{{ card.information }}</td>
                                <td>
                                    <button class="btn btn-sm btn-danger">
                                        <i class="bi bi-trash"></i>
                                    </button>
                                </td>
                            </tr>
                            {% else %}
                            <tr>
                                <td colspan="3" class="text-center">暂无最近录入的卡片</td>
                            </tr>
                            {% endif %}
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
    
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3
